package com.wowoai.common.factoy;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截所有的请求
 */
@Configuration
public class WoWoAIWebMvcConfigurer implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new WoWoAIHandlerInterceptor())
                .addPathPatterns("/**").excludePathPatterns("/static/**");
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("GET", "POST", "PUT", "DELETE")
                .allowedHeaders("Accept", "Accept-Encoding", "Authorization",
                        "Connection", "content-type", "Host",
                        "Sec-Fetch-Mode", "Sec-Fetch-Site", "User-Agent", "cookie")
                .allowCredentials(true)
                .maxAge(3600);
    }
}
